package com.javashizhan.demo.restclient.server;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import com.javashizhan.demo.restclient.domain.ResponseResult;
import com.javashizhan.demo.restclient.domain.User;

/**
 * 
 * @Description: 模拟server端controller给客户端调用
 *
 * @author 飞流
 * @date 2019年8月11日
 * @知识星球 Java实战营
 * @微信公众号 JAVA栈实战营
 * @站点 http://javashizhan.com/
 *
 */

@RestController
public class UserController {

	@PostMapping("/findUserByName")
	public ResponseResult<User> findUserByName(@RequestBody String userName) throws Exception {
		ResponseResult<User> response = new ResponseResult<User>();
		User user = new User();
		user.setUserName(userName);
		user.setAge((int) (Math.random() * 50));
		response.setResultObject(user);
		return response;
	}

	@PostMapping("/createUser")
	public ResponseResult<Void> createUser(@RequestBody User user) throws Exception {
		ResponseResult<Void> response = new ResponseResult<Void>();
		response.setResultMsg("Create user success.");
		return response;
	}
}
